/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.manager.view;

import br.com.foxline.model.City;
import br.com.foxline.model.Construction;
import br.com.foxline.model.Customer;
import br.com.foxline.service.CityService;
import br.com.foxline.service.ConstructionService;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author luciano
 */
@ManagedBean
@ViewScoped
public class ManagerViewCostruction implements Serializable{
    
    private Construction construction;
    @EJB
    private ConstructionService constructionService;
    @EJB
    private CityService cityService;
    
    private List<Customer> customers;
    private City city;
    
    @PostConstruct
    public void init(){
        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        String constructionId = params.get("constructionId");
        this.construction = constructionService.find(Long.valueOf(constructionId)); 
        this.customers = this.construction.getCustumers();
        this.city = new City();
        if (this.construction.getAddress() != null) {
            if (this.construction.getAddress().getCity() != null) {
                this.city = cityService.find(this.construction.getAddress().getCity().getId());
            }
        }
    }

    public Construction getConstruction() {
        return construction;
    }

    public void setConstruction(Construction construction) {
        this.construction = construction;
    }

    public List<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(List<Customer> customers) {
        this.customers = customers;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }
    
    
}
